package president;

import home.HomePage;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;




import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import controllers.Event;

public class ViewEvents extends WebPage {
	
	Reader reader = Resources.getResourceAsReader("sqlMapConfig.xml");
	SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);

	public ViewEvents() throws IOException, SQLException {
		
Form form = new Form("viewEventsForm");
		
		List<Event> events = (List<Event>)sqlMap.queryForList("Event.getAll");
		
		
		ListView eachEvent = new ListView("eachEvent",events) {
			private static final long serialVersionUID = 1L;
			
			
			
			protected void populateItem(ListItem item) {
				final Event event = (Event) item.getModelObject();
				System.out.println(event.getEventid());
				System.out.println(event.getEvent_details());
				System.out.println(event.getEvent_time());
				System.out.println(event.getEvent_title());
				System.out.println(event.getEvent_date());
				item.add(new Label("eventid", Integer.toString(event.getEventid())));
				item.add(new Label("etitle", event.getEvent_title()));
				item.add(new Label("evenue", event.getEvent_venue()));
				item.add(new Label("edate", event.getEvent_date()));
				item.add(new Label("etime", event.getEvent_time()));
				item.add(new Label("edetails", event.getEvent_details()));
				item.add(new Label("uploadedBy", event.getUpload_by()));
				item.add(new Label("uploadedDate", event.getUpload_date()));
			}
		};
		
		add(new BookmarkablePageLink("logoutPage", HomePage.class));
		add(new BookmarkablePageLink("home", PresidentHome.class));
		add(new BookmarkablePageLink("add", AddEvent.class));
		
		form.add(eachEvent);
		add(form);
		
	}
}
